package com.green.card.base;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by admin on 2018/1/25.
 */

public abstract class BaseFragment extends Fragment {
    public Activity context;

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        this.context = activity;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable
            Bundle savedInstanceState) {
        return initViews(inflater, container);
    }

    private View initViews(LayoutInflater inflater, ViewGroup container) {
        int contentView = setContentView();
        View rootView = inflater.inflate(contentView, container, false);
        return rootView;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        findView(view);
        initData(context);
        setListener();
    }

    /**
     * 获取layout id
     * @return
     */
    protected abstract int setContentView();

    /**
     * findViewById
     * @param view
     */
    public abstract void findView(View view) ;

    /**
     * 初始化数据
     * @param context
     */
    protected abstract void initData(Activity context);

    public void setListener() {

    }
}
